<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .register {
            width: 600px;
            margin: 100px auto;
        }
        
        .message {
            /* 默认样式 */
            display: inline-block;
            font-size: 12px;
            color: #999;
            padding-left: 20px;
            background: url(素材/mess.png) no-repeat left center;
        }
        
        .wrong {
            /* 错误样式 */
            color: red;
            background-image: url(素材/wrong.png);
        }
        
        .right {
            /* 正确样式 */
            color: green;
            background-image: url(素材/right.png);
        }
    </style>
</head>

<body>
    <div class="register">
        <input type="password" class="ipt">
        <p class="message">请输入6~16位密码</p>
    </div>
    <script>
        var ipt = document.querySelector('.ipt');
        var messge = document.querySelector('.message');
        ipt.onblur = function() { // 失去焦点
            // 更具表单内容的长度
            if (this.value.length < 6 || this.value.length > 16) {
                // console.log('错误');
                messge.className = 'message wrong';
                messge.innerHTML = '您输入的位数不对要求6-16位'
            } else {
                messge.className = 'message right';
                messge.innerHTML = '输入正确'
            }
        }
    </script>
</body>

</html>